package com.ruoyi.web.controller.memberManagement;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.StoreMemberCustomDiscount;
import com.ruoyi.system.service.IStoreMemberCustomDiscountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 门店会员另设折扣（存储各门店的独立会员折扣配置）Controller
 *
 * @author ruoyi
 * @date 2025-05-14
 */
@Api(tags="门店会员另设折扣")
@RestController
@RequestMapping("/system/storeMemberCustomDiscount")
public class StoreMemberCustomDiscountController extends BaseController
{
    @Autowired
    private IStoreMemberCustomDiscountService storeMemberCustomDiscountService;

    /**
     * 查询门店会员另设折扣列表
     */
    @ApiOperation("查询门店会员另设折扣列表")
    @PreAuthorize("@ss.hasPermi('system:discount:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String storeName)
    {
        startPage();
        List<StoreMemberCustomDiscount> list = storeMemberCustomDiscountService.selectStoreMemberCustomDiscountListByName(storeName);
        return getDataTable(list);
    }

    /**
     * 导出门店会员另设折扣列表
     */
    @ApiOperation("导出门店会员另设折扣列表")
    @PreAuthorize("@ss.hasPermi('system:discount:export')")
    @Log(title = "门店会员另设折扣（存储各门店的独立会员折扣配置）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String storeName)
    {
        List<StoreMemberCustomDiscount> list = storeMemberCustomDiscountService.selectStoreMemberCustomDiscountListByName(storeName);
        ExcelUtil<StoreMemberCustomDiscount> util = new ExcelUtil<StoreMemberCustomDiscount>(StoreMemberCustomDiscount.class);
        util.exportExcel(response, list, "门店会员另设折扣（存储各门店的独立会员折扣配置）数据");
    }

    /**
     * 获取门店会员另设折扣详细信息
     */
    @ApiOperation("获取门店会员另设折扣详细信息")
    @PreAuthorize("@ss.hasPermi('system:discount:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(storeMemberCustomDiscountService.selectStoreMemberCustomDiscountById(id));
    }

    /**
     * 新增门店会员另设折扣列表
     */
    @ApiOperation("新增门店会员另设折扣列表")
    @PreAuthorize("@ss.hasPermi('system:discount:add')")
    @Log(title = "门店会员另设折扣（存储各门店的独立会员折扣配置）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoreMemberCustomDiscount storeMemberCustomDiscount)
    {
        return toAjax(storeMemberCustomDiscountService.insertStoreMemberCustomDiscount(storeMemberCustomDiscount));
    }

    /**
     * 修改门店会员另设折扣列表
     */
    @ApiOperation("修改门店会员另设折扣列表")
    @PreAuthorize("@ss.hasPermi('system:discount:edit')")
    @Log(title = "门店会员另设折扣（存储各门店的独立会员折扣配置）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoreMemberCustomDiscount storeMemberCustomDiscount)
    {
        return toAjax(storeMemberCustomDiscountService.updateStoreMemberCustomDiscount(storeMemberCustomDiscount));
    }

    /**
     * 删除门店会员另设折扣列表
     */
    @ApiOperation("删除门店会员另设折扣列表")
    @PreAuthorize("@ss.hasPermi('system:discount:remove')")
    @Log(title = "门店会员另设折扣（存储各门店的独立会员折扣配置）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(storeMemberCustomDiscountService.deleteStoreMemberCustomDiscountByIds(ids));
    }
}
